<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title a m-cf">货款列表</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom am-cf">
                        <form class="toolbar-form" action="">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <?php $sid = $request->get('sid') ?: null; ?>
                                        <select name="sid"
                                                data-am-selected="{searchBox: 1, btnSize: 'sm',  placeholder: '供应商', maxHeight: 400}">
                                            <option value=""></option>
                                            <?php if (isset($supplierList)): foreach ($supplierList as $first): ?>
                                                <option value="<?= $first['id'] ?>"
                                                    <?= $sid == $first['id'] ? 'selected' : '' ?>>
                                                    <?= $first['name'] ?></option>
                                            <?php endforeach; endif; ?>
                                        </select>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <?php $jkzt = $request->get('jkzt') ?: null; ?>
                                        <select name="jkzt"
                                                data-am-selected="{searchBox: 1, btnSize: 'sm',  placeholder: '结款状态', maxHeight: 400}">
                                            <option value=""></option>
                                                <option value="0" <?= $jkzt == 0 ? 'selected' : '' ?>>未结款</option>
                                                <option value="1" <?= $jkzt == 1 ? 'selected' : '' ?>>已结款</option>
                                        </select>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入供应商联系人/电话"
                                                   value="<?= $request->get('search') ?>">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search"
                                                        type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="am-scrollable-horizontal am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                            <thead>
                            <tr>
                                <th>供应商ID</th>
                                <th>供应商联系人</th>
                                <th>联系电话</th>
                                <th>微信昵称</th>
                                <th>小程序openid</th>
                                <th>标题</th>
                                <th>货款清单</th>
                                <th>货款金额</th>
                                <th>付款方式</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle"><?= $item['id'] ?></td>
                                    <td class="am-text-middle"><?= $item['name'] ?></td>
                                    <td class="am-text-middle"><?= $item['tel'] ?></td>
                                    <td class="am-text-middle"><?= $item['nickName'] ?></td>
                                    <td class="am-text-middle"><?= $item['open_id'] ?></td>
                                    <td class="am-text-middle"><?= $item['title'] ?></td>
                                    <td class="am-text-middle">
                                        <a href="<?= url('Supplier/picLists', ['hkid' => $item['id']]) ?>">查看</a>
                                    </td>
                                    <td class="am-text-middle"><?= $item['pay_type'] ?></td>
                                    <td class="am-text-middle"><?= $item['money'] ?></td>
                                    <td class="am-text-middle">
                                        <span class="am-badge am-badge-<?= $item['status'] ? 'success' : 'warning' ?>">
                                               <?= $item['status'] ? '已结款' : '未结款' ?>
                                           </span>
                                    </td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <?php if ($item['status'] == 0) : ?>
                                                <?php if (checkPrivilege('Supplier/money')): ?>
                                                    <a class="j-money tpl-table-black-operation-del"
                                                       data-id="<?= $item['id'] ?>" href="javascript:void(0);">确认付款
                                                    </a>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                            <?php if ($item['status'] == 0) : ?>
                                                <?php if (checkPrivilege('Supplier/wechat_pay')): ?>
                                                    <a class="j-wechat-pay tpl-table-black-operation-green"
                                                       data-id="<?= $item['id'] ?>" href="javascript:void(0);">微信付款
                                                    </a>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; else: ?>
                                <tr>
                                    <td colspan="11" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<script>
    $(function () {

        /**
         * 确认打款
         */
        $('.j-money').click(function () {
            var id = $(this).data('id');
            var url = "<?= url('Supplier/money') ?>";
            layer.confirm('确定已付款吗？', {title: '友情提示'}, function (index) {
                $.post(url, {id: id}, function (result) {
                    result.code === 1 ? $.show_success(result.msg, result.url)
                        : $.show_error(result.msg);
                });
                layer.close(index);
            });
        });

        /**
         * 微信付款
         */
        $('.j-wechat-pay').click(function () {
            var id = $(this).data('id');
            var url = "<?= url('Supplier/wechat_pay') ?>";
            layer.confirm('该操作 将使用微信支付企业付款到零钱功能，确定打款吗？', {title: '友情提示'}, function (index) {
                $.post(url, {id: id}, function (result) {
                    result.code === 1 ? $.show_success(result.msg, result.url)
                        : $.show_error(result.msg);
                });
                layer.close(index);
            });
        });

    });
</script>